package com.xinke.juc.case04;

import com.xinke.juc.util.Sleeper;
import lombok.extern.slf4j.Slf4j;

/**
 * @Author：xinke
 * @Date：2025/10/3
 * @Desc:
 */
@Slf4j
public class BigRoomDemo02 {

    public static void main(String[] args) {
        BigRoom02 room = new BigRoom02();
        new Thread(() -> {
            room.sleep();
        }, "小南").start();
        new Thread(() -> {
            room.study();
        }, "小女").start();
    }
}

@Slf4j
class BigRoom02 {
    private final Object studyRoom = new Object();
    private final Object bedRoom = new Object();
    public void sleep() {
        synchronized (bedRoom) {
            log.info("sleeping 2 小时");
            Sleeper.sleep(2);
        }
    }

    public void study() {
        synchronized (studyRoom) {
            log.info("study 1 小时");
            Sleeper.sleep(1);
        }
    }
}
